package com.chen.lifepic;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.Menu;

import com.chen.lifepic.DataProvider.RemoteGrideViewProvider;
import com.chen.lifepic.LargeViewFragment.SlideShowFragment;
import com.chen.lifepic.ThumbnailFragment.RemoteGrideFragment;
import com.chen.lifepic.utils.APPCommonDef;
import com.chen.lifepic.utils.APPCommonDef.GirlType;

public class LifePic extends FragmentActivity {
	public static final int FRAGEMTN_ID_GRID_VIEW = 1;

	public static final int FRAGMENT_ID_LARGE_VIEW = 2;

	RemoteGrideViewProvider _remoteGrideViewProvider = null;

	RemoteGrideFragment _remoteGrideFragment = null;

	SlideShowFragment _slideShowFragment = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		_remoteGrideViewProvider = new RemoteGrideViewProvider(
				this.getIntent().getIntExtra(APPCommonDef.INTENT_GIRL_TYPE, GirlType.Girl_Cute_Girl));
		setContentView(R.layout.activity_life_pic);
		initFragment();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		if (null != _remoteGrideViewProvider) {
			_remoteGrideViewProvider.destroy();
			_remoteGrideViewProvider = null;
		}
	}

	public RemoteGrideViewProvider getRemoteGrideViewProvider() {
		return _remoteGrideViewProvider;
	}

	void initFragment() {
		_remoteGrideFragment = new RemoteGrideFragment();
		_slideShowFragment = new SlideShowFragment();

		FragmentManager fragmentManager = getSupportFragmentManager();
		FragmentTransaction currentTransaction = fragmentManager.beginTransaction();

		currentTransaction.add(R.id.RemoteGrideFragment, _remoteGrideFragment);
		// currentTransaction.add(R.id.LargeViewFragment, _slideShowFragment);
		currentTransaction.commit();
	}

	public void jumpToFragment(int id) {
		FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
		// ft.setCustomAnimations(
		// android.R.animator.fade_in, android.R.animator.fade_out);
		// ft.show(_slideShowFragment);
		// ft.hide(_remoteGrideFragment);
		ft.replace(R.id.RemoteGrideFragment, _slideShowFragment);
		ft.addToBackStack(null);
		ft.commit();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.life_pic, menu);
		return true;
	}
}
